package com.ssf.framework.resource;

import com.ssf.framework.config.ConfigTemplate;
import com.ssf.framework.config.ResourceConfig;
import org.n3r.diamond.client.Miner;

import static org.apache.commons.lang3.StringUtils.removeEnd;
import static org.apache.commons.lang3.StringUtils.removeStart;

/**
 * Created by liolay on 15-7-27.
 */
public class ResFun {


    public static String r(String relativeResPath) {
        ConfigTemplate configTemplate = ConfigTemplate.getConfigBean();
        ResourceConfig resourceConfig = configTemplate.getResourceConfig();

        return new StringBuilder(removeEnd(resourceConfig.getPrefix(), "/"))
                .append("/").append(removeStart(relativeResPath, "/"))
                .append("?v=").append(resourceConfig.getVersion()).toString(); // .append("&time=").append(System.currentTimeMillis())

    }

    public static String config(String groupId, String dataId, String key) {
        return new Miner().getMiner(groupId, dataId).getString(key);
    }

}
